package com.mc.sort;

import java.util.Arrays;

/**
 * @Description: 希尔排序
 * @Author: MoChen
 */
public class ShellSort {
    public static void main(String[] args) {
        int[] arrs = {1, 2, 5, 3, 6, 7, 4};
        ShellSort ss = new ShellSort();
        System.out.println(Arrays.toString(ss.shellSort(arrs)));
    }

    /**
     * 希尔排序
     */
    public int[] shellSort(int[] arrs){
        for(int dk = arrs.length / 2; dk >= 1; dk /= 2){
            for(int i = dk + 1; i < arrs.length; i++){
                int j = i;
                int temp = arrs[j];
                for(j = i; j >= dk && arrs[i - dk] > temp; i -= dk){
                    arrs[i] = arrs[i - dk];
                }
                arrs[i] = temp;
            }
        }
        return arrs;
    }
}
